package com.tomecode.rvr.generator.filter;

import java.io.File;

import com.tomecode.rvr.generator.Config;

/**
 * 
 * Filter for all folders in {@link Config#getWorkingDir()}
 * 
 * 
 @author Frastia Tomas
 * 
 */
public final class DirNamePropertyFilter {



	private boolean ignoreStart;

	private boolean ignoreEnd;

	private String word;

	public DirNamePropertyFilter(String orginalWord) {
		if (orginalWord.startsWith("*")) {
			ignoreStart = true;
			orginalWord = orginalWord.substring(1, orginalWord.length());
		}
		if (orginalWord.endsWith("*")) {
			ignoreEnd = true;
			orginalWord = orginalWord.substring(0, orginalWord.length() - 1);
		}
		word = orginalWord;
	}

	public final boolean isStarStarted() {
		return ignoreStart;
	}

	public final boolean isStarEnded() {
		return ignoreEnd;
	}

	public final String getWord() {
		return word;
	}

	public final boolean matche(File file) {
		if (ignoreStart && ignoreEnd) {
			return file.getPath().contains(word);
		} else if (ignoreStart && !ignoreEnd) {
			return file.getPath().endsWith(word);
		} else if (!ignoreStart && ignoreEnd) {
			return file.getPath().startsWith(word);
		}
		return file.getPath().equals(word);
	}
}
